<?php
/**
*
* @package phpBB3 Social Network
* @author  kmklr72
* @copyright (c) 2009 kmklr72
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/*
*
*  The following code is from the Simple Profile Comments MOD by platinum_2007 (Ian Taylor)
*  All credits to him for this code
*
*/

$user_id = request_var('u', 0);
$start = request_var('friends', 0);
$limit = $config['number_friends'];

$sql = 'SELECT u.user_avatar, u.username, u.user_colour, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, z.user_id, z.zebra_id, z.friend
	FROM ' . USERS_TABLE . ' u, ' . ZEBRA_TABLE . ' z
	WHERE u.user_id = z.zebra_id
	AND z.friend = 1
	AND z.user_id = ' . $user_id;
$result = $db->sql_query_limit($sql, $limit, $start);

while ($row_av = $db->sql_fetchrow($result))
{
	$avatar_fri = get_user_avatar($row_av['user_avatar'], $row_av['user_avatar_type'], $row_av['user_avatar_width'], $row_av['user_avatar_height']);
	$fri_id = $row_av['zebra_id'];
	$av_size_size = $config['friend_avatar_size'];

	$template->assign_block_vars('fri',array(
		'FRI_ID'		=> $row_av['zebra_id'],
		'FRI_AV'		=> $avatar_fri,
		'USERNAME'		=> $row_av['username'],
		'WIDTH'			=> $config['friend_avatar_size'],
		'USER_COLOR'	=> $row_av['user_colour'],
		'AV_LINK'		=> append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&u=$fri_id"),      
		'FRI_AV_THUMB'	=> ($row_av['user_avatar']) ? get_user_avatar($row_av['user_avatar'], $row_av['user_avatar_type'], ($row_av['user_avatar_width'] > $row_av['user_avatar_height']) ? $av_size_size : ($av_size_size / $row_av['user_avatar_height']) * $row_av['user_avatar_width'], ($row_av['user_avatar_height'] > $row_av['user_avatar_width']) ? $av_size_size : ($av_size_size / $row_av['user_avatar_width']) * $row_av['user_avatar_height']) : '',
	));
}

// count some stuff up for the pagination
$profile = request_var('u', 0);
$sql = 'SELECT COUNT(zebra_id) AS number_friends
	FROM '. ZEBRA_TABLE ."
	WHERE user_id = $profile
	AND friend = 1";
$result = $db->sql_query($sql);
$pagination_friend = append_sid($phpbb_root_path . 'memberlist.' . $phpEx ,'mode=viewprofile&amp;u='.$user_id);

$total_friends = $db->sql_fetchfield('number_friends');
$db->sql_freeresult($result);

$template->assign_vars(array(
	'F_PAGINATION'		=> $sn->paginate_this($pagination_friend, $total_friends, $limit, $start, false, '', 'friends', $page_ary),
	'PAGE_NUMBER_F'		=> on_page($total_friends, $limit, $start),
));

?>